package xyz.jcat.common;

import xyz.jcat.common.exception.BusinessException;
import xyz.jcat.common.util.ObjectUtils;

import java.util.Objects;

public interface Assert {

    BusinessException newException();
    BusinessException newException(String message);

    default void isNull(Object obj) {
        isNull(obj, null);
    }

    default void isNull(Object obj, String message) {
        if(Objects.isNull(obj)) {
            throw newException(message);
        }
    }

    default void notNull(Object obj) {
        notNull(obj, null);
    }

    default void notNull(Object obj, String message) {
        if(ObjectUtils.notNull(obj)) {
            throw newException(message);
        }
    }

    default void isTrue(boolean bool) {
        isTrue(bool, null);
    }

    default void isTrue(boolean bool, String message) {
        if(bool) {
            throw newException(message);
        }
    }

    default void isFalse(boolean bool) {
        isFalse(bool, null);
    }

    default void isFalse(boolean bool, String message) {
        isTrue(!bool, message);
    }
}
